package com.elitel.frame.task;

import com.elitel.frame.base.service.Server2CacheService;
import com.elitel.frame.main.entity.vo.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author mulis
 */
@Component("server2CacheScheduler")
public class Server2CacheScheduler {


    @Resource
    private Server2CacheService server2CacheService;

    private static final Logger logger = LoggerFactory.getLogger(Server2CacheScheduler.class);

    /**
     * 刷新到缓存 每5分钟执行一次
     */
    public JsonResult saveServerInfo2Cache() {
        JsonResult jsonResult = new JsonResult();
        try {
            logger.info("开始刷新到缓存");
            server2CacheService.saveServerInfo2Cache();
            server2CacheService.saveAppInfo2Cache();
            server2CacheService.saveAppServerInfo2Cache();
            jsonResult.setSuccess(true);
            logger.info("结束刷新到缓存");
        } catch (Exception e) {
            logger.error("刷新到缓存失败", e);
            jsonResult.setSuccess(false);
            jsonResult.setMsg(e.getMessage());
        }
        return jsonResult;
    }


}
